home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUT1-9.ZIP / C4TUT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-12-14  |  8KB  |  259 lines

  1. (*
  2. Well folks, here it is - the long awaited for Chain-4 trainer. The
  3. routines are commented so I'm not going to say too much more here,
  4. except a few things.
  5.  
  6. 1: If ya don't understand this (not suprising its bloody cryptic!)
  7.    then if ur serious go out and buy - Programming the EGA & VGA Cards
  8.    I don't know who the book is by, so don't ask. Perhaps you know Greg?
  9.  
  10. 2: The code is unoptimised. I wrote it specifically for this conf. and
  11.    I'm buggered if I'm gonna give out my wholely (sp? ahh stuff it :-))
  12.    optimised code. If you want it faster, OPTIMISE IT!!
  13.    HINT: Its faster to load ax, with a low byte/high byte combination
  14.          and out a word instead of a byte at a time. If u don't know
  15.          what I'm talking about, too bad :-)
  16.  
  17. 3: If you use/like/whatever this code, please give Asphyxia a mention.
  18.    It wos bloody hard work figuring out how all this cr*p works, we
  19.    couldn't have done it with out a little guidence (thanx Gregie Poo).
  20.  
  21. 4: LiveWire got interested in the whole tut/trainer idea and MAY be
  22.    putting together a doc on how the whole thing works, including
  23.    Pel-Panning which I haven't included here.
  24.  
  25.  
  26. 5: Good luck with the code, and if you write anything with it, I'd
  27.    appreciate having a look at it :-). Feel free to direct any comments
  28.    about the code to me in this conf. Or at one of the contact addresses
  29.    given in the code.
  30.  
  31.  
  32. l8rs
  33. EzE / Asphyxia
  34.  
  35.  
  36.  
  37. --------------------------------=[ Cut Here ]=-------------------------
  38. *)
  39. {$X+,G+}
  40. Program Chain4_Tut;
  41. Uses
  42.    Crt;
  43.  
  44.  
  45. Const
  46.    Size : Byte = 80;
  47.  
  48.  
  49. Var Loop : Integer;
  50.  
  51.  
  52.  
  53. Procedure Init_C4; Assembler;
  54. Asm
  55.    mov   ax, 0013h
  56.    int   10h               { set up bios initially for 13h            }
  57.  
  58.    mov   dx, 03c4h         { Sequencer Address Register               }
  59.    mov   al, 4             { Index 4 - Memory mode                    }
  60.    out   dx, al            { select it.                               }
  61.    inc   dx                { 03c5h - here we set the mem mode.        }
  62.    in    al, dx            { get whats already inside the reg         }
  63.    and   al, 11110111b     { un-set 4th bit - chain4                  }
  64.    out   dx, al
  65.  
  66.    mov   dx, 3d4h
  67.    mov   al, 13h           { Offset Register - allocates amt. mem for }
  68.    out   dx, al            { 1 displayable line as - length div 8, so }
  69.    inc   dx                { we use 80 (80*8) = 640 = 2 pages across  }
  70.    mov   al, [Size]        { and cause of chain-4 i.e. 256k display   }
  71.    out   dx, al            { mem, 2 pages down for four pages         }
  72.  
  73.                            { NOTE: setting AL above to 40 selects 1   }
  74.                            { page across and four down (nice for      }
  75.                            { 1942 type scrolling games) and setting   }
  76.                            { AL to 160 selects 4 pages across and 1   }
  77.                            { down, nice for horizontal scrolling      }
  78.  
  79. End;
  80.  
  81.  
  82.  
  83. Procedure Cls_C4; Assembler;
  84. Asm
  85.    mov   dx, 03c4h         { 03c4h                                    }
  86.    mov   al, 2             { Map Mask Register                        }
  87.    out   dx, al
  88.    inc   dx
  89.    mov   al, 00001111b     { Select all planes to write to            }
  90.    out   dx, al            { Doing this to clear all planes at once   }
  91.  
  92.    mov   ax, 0a000h
  93.    mov   es, ax
  94.    xor   di, di            { set es:di = Screen Mem                   }
  95.    mov   ax, 0000h         { colour to put = black                    }
  96.    mov   cx, 32768         { 32768 (words) *2 = 65536 bytes - vga mem }
  97.    cld
  98.    rep   stosw             { clear it                                 }
  99. End;
  100.  
  101.  
  102.  
  103. Procedure PutPixel_C4(X, Y : Integer; Col : Byte); Assembler;
  104. Asm
  105.    mov   ax, [Y]           { Y val multiplied by...                   }
  106.    xor   bx, bx
  107.    mov   bl, [Size]        { Size....                                 }
  108.    shl   bx, 1             { *2 - just 'cause! (I can't remember why!)}
  109.    mul   bx
  110.    mov   bx, ax
  111.  
  112.    mov   ax, [X]
  113.    mov   cx, ax
  114.    shr   ax, 2
  115.    add   bx, ax            { add X val div 4 (four planes)            }
  116.  
  117.    and   cx, 00000011b     { clever way of finding x mod 4, i.e.      }
  118.    mov   dx, 03c4h         { which plane we're in.                    }
  119.    mov   al, 2             { then use 03c4h index 2 - write plane sel.}
  120.    out   dx, al            { to set plane to write to.                }
  121.    mov   al, 1             { plane to write to = 1 shl (X mod 4)      }
  122.    shl   al, cl
  123.    inc   dx
  124.    out   dx, al
  125.  
  126.    mov   ax, 0a000h
  127.    mov   es, ax
  128.    mov   al, [Col]
  129.    mov   es: [bx], al      { then write pixel.                        }
  130. End;
  131.  
  132.  
  133. Function GetPixel_C4(X, Y : Integer): Byte; Assembler;
  134. Asm
  135.    mov   ax, [Y]           { Y val multiplied by...                   }
  136.    xor   bx, bx
  137.    mov   bl, [Size]        { Size....                                 }
  138.    shl   bx, 1             { *2 - just 'cause! (I can't remember why!)}
  139.    mul   bx
  140.    mov   bx, ax
  141.  
  142.    mov   ax, [X]
  143.    mov   cx, ax
  144.    shr   ax, 2
  145.    add   bx, ax            { add X val div 4 (four planes)            }
  146.  
  147.    and   cx, 00000011b     { clever way of finding x mod 4, i.e.      }
  148.    mov   dx, 03c4h         { which plane we're in.                    }
  149.    mov   al, 4h            { then use 03c4h index 4 - read plane sel. }
  150.    out   dx, al            { to set plane to read from.               }
  151.    mov   al, cl            { Plane to read from = X mod 4             }
  152.    inc   dx
  153.    out   dx, al
  154.  
  155.    mov   ax, 0a000h
  156.    mov   es, ax
  157.    mov   al, es: [bx]      { then return pixel read                   }
  158. End;
  159.  
  160.  
  161.  
  162. Procedure MoveScr_C4(X,Y : Integer); Assembler;
  163. Asm
  164.    mov   ax, [Y]           { Y val multiplied by...                   }
  165.    xor   bx, bx
  166.    mov   bl, [Size]        { Size....                                 }
  167.    shl   bx, 1             { *2 - just 'cause! (I can't remember why!)}
  168.    mul   bx
  169.    mov   bx, ax
  170.  
  171.    add   bx, [X]           { Add X val                                }
  172.  
  173.    mov   dx, 03d4h
  174.    mov   al, 0ch           { CRTC address reg.                        }
  175.    out   dx, al            { Start Address High Reg.                  }
  176.    inc   dx
  177.    mov   al, bh            { send high byte of start address.         }
  178.    out   dx, al
  179.  
  180.    dec   dx
  181.    mov   al, 0dh           { Start Address Low Reg.                   }
  182.    out   dx, al
  183.    inc   dx
  184.    mov   al, bl            { send low byte of start address.          }
  185.    out   dx, al
  186.  
  187. End;
  188.  
  189.  
  190. Procedure SetText; Assembler;
  191. Asm
  192.    mov   ax, 0003h
  193.    int   10h
  194. End;
  195.  
  196. Procedure Creds;
  197. Begin
  198.    SetText;
  199.    While KeyPressed do ReadKey;
  200.  
  201.    Asm
  202.       mov   ah, 1
  203.       mov   ch, 1
  204.       mov   cl, 0
  205.       int   10h
  206.    End;
  207.  
  208.    WriteLn('Chain-4 Trainer...');
  209.    WriteLn('By EzE of Asphyxia.');
  210.    WriteLn;
  211.    WriteLn('Contact Us on ...');
  212.    WriteLn;
  213.    WriteLn;
  214.    WriteLn('the Asphyxia BBS (031) - 7655312');
  215.    WriteLn;
  216.    WriteLn('Email :       eze@');
  217.    WriteLn('         asphyxia@');
  218.    WriteLn('          edwards@');
  219.    WriteLn('           bailey@');
  220.    WriteLn('          mcphail@');
  221.    WriteLn('                  beastie.cs.und.ac.za');
  222.    WriteLn;
  223.    WriteLn('or  peter.edwards@datavert.co.za');
  224.    WriteLn;
  225.    WriteLn('Write me snail-mail at...');
  226.    WriteLn('P.O. Box 2313');
  227.    WriteLn('Hillcrest');
  228.    WriteLn('Natal');
  229.    WriteLn('3650');
  230.    Asm
  231.       mov   ah, 1
  232.       mov   ch, 1
  233.       mov   cl, 0
  234.       int   10h
  235.    End;
  236.  
  237. End;
  238.  
  239.  
  240.  
  241.  
  242. Begin
  243.    Init_C4;
  244.    Cls_C4;
  245.    Repeat
  246.       Putpixel_C4(Random(320),Random(200),Random(256)+1);
  247.    Until KeyPressed;
  248.    For Loop := 0 to 80 do
  249.    begin
  250.       MoveScr_C4(0,Loop);
  251.       Delay(10);
  252.    End;
  253.    ReadKey;
  254.    Loop := GetPixel_C4(100,100);
  255.    Creds;
  256.    WriteLn('Colour at location X:100, Y:100 was: ',Loop);
  257. End.
  258.  
  259. --------------------------------=[ Cut Here ]=-------------------------